package wc.servicelet; /**
 * @ClassName:${NAME}
 * @Author: 鹿建文
 * @Date: 2022/4/8  - 17:42
 * @Describe:
 */

import wc.Service.AdminService;
import wc.Service.Impl.AdminServiceImpl;
import wc.domain.Admin;
import wc.domain.User;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(urlPatterns = "/addUser")
public class AddUserServlet extends HttpServlet {
    private AdminService adminService=new AdminServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("postget");
        Integer id = Integer.valueOf(request.getParameter("id"));
        boolean gender = Boolean.parseBoolean(request.getParameter("gender"));
//        Integer jifen = Integer.valueOf(request.getParameter("jifen"));
        String tel = request.getParameter("tel");
        String name = request.getParameter("name");
        Integer credits=100;
        User user = new User(id,name,gender,tel,credits);
//        user.setcredits(jf);
        boolean res =false;
        try {
            res = adminService.addUser(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (res){
            response.sendRedirect("index.html");

        } else {
            response.sendRedirect("erro.html");

        }
    }
}
